package com.wanglv.test;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SQLiteHelper extends SQLiteOpenHelper {

    public SQLiteHelper(Context context) {
        super(context, "user.db", null, 2);
        Version();
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("create table user(userid integer primary key autoincrement,username varchar(10) not null,password varchar(10) not null)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        if (i1==2){
            sqLiteDatabase.execSQL("alter table user add sex varchar(2)");
        }
    }


    /*
    此方法返回数据库版本
     */
    public int Version(){
        return 2;
    }

}
